#include <iostream>
//#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <sstream>
#include <string>
#include <ctime>
#include <cstdlib>
#include <iomanip>

using namespace std;

unsigned int INC_COEF_PISOS = 0.5;
unsigned int INC_CANT_AUTOS_LIVIANOS = 2;
unsigned int INC_CANT_AUTOS_PESADOS = 2;


string lineaAutos(float paramIni, int n) {
  	stringstream ss;
    float param = paramIni;
    srand((unsigned)time(0));
	int cant = 0;
    INC_CANT_AUTOS_LIVIANOS = paramIni/10*(rand()%4);
	while (cant < n) {
        ss <<setprecision(20)<< paramIni + INC_CANT_AUTOS_LIVIANOS << " ";
        cant++;
	}

	return ss.str();
}

string lineaK(float paramIni, int n) {
  	stringstream ss;
    srand((unsigned)time(0));
	int cant = 0;
    INC_COEF_PISOS = paramIni/10*(rand()%4);

	while (cant < n) {
        ss<<setprecision(20) << paramIni + INC_COEF_PISOS << " ";
        cant++;
	}

	return ss.str();
}


void testEstacionamiento(int n, int m0, int ml, int mp, float kIni, float lIni, float pIni, string fileName) {

	ofstream myfile;
	myfile.open(fileName.c_str(), ios::out);

    stringstream ss;
    ss << n << " " << m0 << " " << ml << " " << mp;
    myfile << ss.str() << endl;


    myfile << lineaK(kIni, n) << endl;
    myfile << lineaAutos(lIni, n) << endl;
    myfile << lineaAutos(pIni, n) << endl;

	myfile.close();
}

int main(int argc, char* argv[]) {
	string fileName;


    if (argc != 9) {
        cout << "Cantidad incorrecta de parametros" << endl;
        cout << "./main n m0 ml mp k_ini l_ini p_ini fileName" << endl;
        cout << "k_ini l_ini p_ini son el coeficiente, cantidad de autos livianos, y cantidad de autos pesados del primer piso" << endl;
    } else {
        int n = atoi(argv[1]);
        int m0 = atoi(argv[2]);
        int ml = atoi(argv[3]);
        int mp = atoi(argv[4]);
        float kIni = atof(argv[5]);
        float lIni = atof(argv[6]);
        float pIni = atof(argv[7]);
        fileName = argv[8];
        fileName = "../archivosPrueba/"+fileName;
        cout<<fileName<<endl;
        remove(fileName.c_str());
        testEstacionamiento(n, m0, ml, mp, kIni, lIni, pIni, fileName);
    }

    return 0;
}
